﻿using HC.Standard.UniversalAudioScheme;
using HC.Standard.UniversalAudioScheme.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace InnerAudioScheme.Models
{
    /// <summary>
    /// 音频json转实体类
    /// </summary>
    public class NotifyAudioInformation: INotifyPropertyChanged
    {
        /// <summary>
        /// 音频类型
        /// </summary>
        private AudioSelectionCondition _audioType;

        public AudioSelectionCondition audioType
        {
            get => _audioType;
            set
            {
                if (_audioType != value)
                {
                    _audioType = value;
                    OnPropertyChanged(nameof(audioType));
                }
            }
        }
        /// <summary>
        /// 音频分组
        /// </summary>       

        private AudioSelectionCondition _audioGroup;

        public AudioSelectionCondition audioGroup
        {
            get => _audioGroup;
            set
            {
                if (_audioGroup != value)
                {
                    _audioGroup = value;
                    OnPropertyChanged(nameof(audioGroup));
                }
            }
        }
        /// <summary>
        /// 音频功能强度
        /// </summary>
    //    public AudioSelectionCondition audioHz { get; set; }

        private AudioSelectionCondition _audioHz;

        public AudioSelectionCondition audioHz
        {
            get => _audioHz;
            set
            {
                if (_audioHz != value)
                {
                    _audioHz = value;
                    OnPropertyChanged(nameof(audioHz));
                }
            }
        }
        /// <summary>
        /// 指定音频序号
        /// </summary>
        private int _serialnumber;

        public int serialnumber
        {
            get => _serialnumber;
            set
            {
                if (_serialnumber != value)
                {
                    _serialnumber = value;
                    OnPropertyChanged(nameof(serialnumber));
                }
            }
        }
        /// <summary>
        /// 音量（范围：0-1）
        /// </summary>
       // public double volume { get; set; }

        private double _volume=1.0;

        public double volume
        {
            get => _volume;
            set
            {
                if (_volume != value)
                {
                    _volume = value;
                    OnPropertyChanged(nameof(volume));
                }
            }
        }
        /// <summary>
        /// 是否顺序播放
        /// </summary>
      //  public bool isSequence { get; set; }

        private bool _isSequence;

        public bool isSequence
        {
            get => _isSequence;
            set
            {
                if (_isSequence != value)
                {
                    _isSequence = value;
                    OnPropertyChanged(nameof(isSequence));
                }
            }
        }
        /// <summary>
        /// 循环次数
        /// </summary>
      //  public int loopCount { get; set; }
        private int _loopCount=1;

        public int loopCount
        {
            get => _loopCount;
            set
            {
                if (_loopCount != value)
                {
                    _loopCount = value;
                    OnPropertyChanged(nameof(loopCount));
                }
            }
        }


        /// <summary>
        /// 音频音轨
        /// </summary>
      //  public int audioTrack { get; set; }


        private int _audioTrack=1;

        public int audioTrack
        {
            get => _audioTrack;
            set
            {
                if (_audioTrack != value)
                {
                    _audioTrack = value;
                    OnPropertyChanged(nameof(audioTrack));
                }
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }


    public class AudioSelectionCondition :INotifyPropertyChanged
    {
        /// <summary>
        /// 选择类型
        /// </summary>
      

        private AudioSelectionType _selectionType;

        public AudioSelectionType selectionType
        {
            get { return _selectionType; }
            set { _selectionType = value; OnPropertyChanged("selectionType"); }
        }

        /// <summary>
        /// 名称
        /// </summary>
        private string _name;

        public string name
        {
            get { return _name; }
            set { _name = value; OnPropertyChanged("name"); }
        }




        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

    }

    /// <summary>
    /// 音频选择类型
    /// </summary>
    public enum AudioSelectionType
    {
        /// <summary>
        /// 等于
        /// </summary>
        Equal,
        /// <summary>
        /// 不等于
        /// </summary>
        NotEqual,
        /// <summary>
        /// 包含
        /// </summary>
        Contains,
        /// <summary>
        /// 不包含
        /// </summary>
        NotContains,
    }


    public class NotifyAudioCombination : INotifyPropertyChanged
    {
        private int _id;
        private string _name;
        private HC.Standard.UniversalAudioScheme.TimeConfiguration? _time;
        private int _count;
        private ObservableCollection<NotifyAudioCombination> _combinations;
        private NotifyAudioInformation _information;

        /// <summary>  
        /// 方案id，可不设置  
        /// </summary>  
        public int id
        {
            get => _id;
            set
            {
                if (_id != value)
                {
                    _id = value;
                    OnPropertyChanged(nameof(id));
                }
            }
        }

        /// <summary>  
        /// 方案名称  
        /// </summary>  
        public string name
        {
            get => _name;
            set
            {
                if (_name != value)
                {
                    _name = value;
                    OnPropertyChanged(nameof(name));
                }
            }
        }

        /// <summary>  
        /// 时间配置  
        /// </summary>  
        public HC.Standard.UniversalAudioScheme.TimeConfiguration time
        {
            get => _time;
            set
            {
                if (_time != value)
                {
                    _time = value;
                    OnPropertyChanged(nameof(time));
                }
            }
        }

        /// <summary>  
        /// 方案播放次数  
        /// </summary>  
        public int count
        {
            get => _count;
            set
            {
                if (_count != value)
                {
                    _count = value;
                    OnPropertyChanged(nameof(count));
                }
            }
        }

        /// <summary>  
        /// 子方案  
        /// </summary>  
        public ObservableCollection<NotifyAudioCombination> combinations
        {
            get => _combinations;
            set
            {
                if (_combinations != value)
                {
                    _combinations = value;
                    OnPropertyChanged(nameof(combinations));
                }
            }
        }

        /// <summary>  
        /// 音频信息  
        /// </summary>  
        public NotifyAudioInformation information
        {
            get => _information;
            set
            {
                if (_information != value)
                {
                    _information = value;
                    OnPropertyChanged(nameof(information));
                }
            }
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class MultiplyBy100Converter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double dValue) // 确保值可以转换为double类型
            {
                return dValue * 100; // 返回值的100倍
            }
            return value; // 如果无法转换，‌返回原始值
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is double number)
            {
                return number / 100;
            }
            return value;
        }
    }

    public class VisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool)
            {
                return (bool)value ? Visibility.Visible : Visibility.Hidden;
            }
            return Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value is Visibility && (Visibility)value == Visibility.Visible;
        }
    }
}
